package rozetka;

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        int[] myArr = {3,2,1,7,0,67,9};




        //int ind = binarySearch(myArr[0], myArr);
         myArr =sortirovka(myArr);
      //  System.out.println(ind);
       // System.out.println(myArr[ind]);
       // System.out.println("bla: "+binarySearch(0,myArr));
        System.out.println(Arrays.toString(myArr));

    }

    public static int binarySearch(int elementToFind, int[] sourceArr)
    {
        int leftBorderIndex = 0;
        int rightBorderIndex = sourceArr.length - 1;
        int count =0;


        while (leftBorderIndex <= rightBorderIndex) {
            int middleIndex = leftBorderIndex + (rightBorderIndex - leftBorderIndex) / 2;
            count ++;
            if (elementToFind < sourceArr[middleIndex]){
                rightBorderIndex = middleIndex - 1;

            }
            else if (elementToFind > sourceArr[middleIndex]) {
                leftBorderIndex = middleIndex + 1;

            } else {
                return count;
                        //(middleIndex; count)
            }
        }

        return -1;
    }

    public static int[] sortirovka(int[] arr) {

        for (int i = arr.length - 1; i >= 1; i--) {
            boolean sorted = true;
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    sorted = false;
                }
            }

            if (sorted) {
                break;
            }
        }
        return arr;
    }
}